﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Chat.Common;
public class RoomListItem : MonoBehaviour
{
    public Room RoomData;
    public Text RoomNameText, RoomIdText,MemberCountText;
    [Header("进入房间按钮")]
    public Button enterRoomBtn;
    private void Awake()
    {
        enterRoomBtn.onClick.AddListener(EnterRoom);
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }
    // Update is called once per frame
    void Update()
    {
        if (RoomData != null)
        {
            RoomIdText.text = RoomData.Id;
            RoomNameText.text = RoomData.Name;
            MemberCountText.text = RoomData.MemberCount.ToString();
        }
    }
    void EnterRoom()
    {
        if(RoomData != null)
        {
            Singleton<UIManager>.GetInstance().GetSingleUI(UIType.ChattingPanelContentType).GetComponent<ChattingPanel>().ChatType = ChatType.Public;
            Singleton<UIManager>.GetInstance().GetSingleUI(UIType.ChattingPanelContentType).GetComponent<ChattingPanel>().ChatObject = RoomData as ChatObject;
            Singleton<CommandSender>.GetInstance().SendControlCmd(ControlType.EnterRoom, RoomData.Id);
            Singleton<CommandSender>.GetInstance().SendControlCmd(ControlType.GetMemList);
            Singleton<ContentManager>.GetInstance().Push(new ChattingPanelContent());
        }
    }
}
